var food_cate_ops = {
    init: function () {
        this.eventBind();
    },
    eventBind: function () {
        var select_h = $('.wrap_search select[name=status]');
        var params = common_ops.getParams();
        var select = "0";
        if (common_ops.isEmpty(params.st)) {
            select = "-1";
        }
        else {
            select = params.st;
        }
        select_h.find('option[value='+ select +']').attr('selected', true);

        $('.wrap_search select[name=status]').change(function () {
            var st = $('.form-group select[name=status]').val();
            window.location.href = '/food/cat?st=' + st;
        });

        $('.remove').click(function () {
            var id = $(this).attr('data-id');
            var callback = {
                'ok': function () {
                    $.ajax({
                        url: '/food/cat-del',
                        type: 'POST',
                        dataType: 'json',
                        data: {
                            'id': id
                        },
                        success: function (data) {
                            if (data['code'] === 200) {
                                common_ops.alert('删除成功！');
                                window.location.href = '/food/cat'
                            }
                            else {
                                common_ops.alert(data['msg']);
                            }
                        },
                        fail: function () {
                            common_ops.alert('操作失败，请重试！');
                        }
                    });
                },
                'cancel': function () {

                }
            };
            common_ops.confirm('确定删除该类目？', callback);
        });
    }
};

$(function () {
    food_cate_ops.init();
});